package com.tencent.albert.weixin.driver.dao;

import com.tencent.albert.weixin.driver.MsgManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;

/**
 * Created by albertzhu on 15/2/13.
 */
public abstract class BaseDao {

    private static Logger logger = LoggerFactory.getLogger(BaseDao.class);

    public Connection getConn() {
        return MsgManager.getConn();
    }

    public void closeConn(ResultSet rs,Statement st,Connection con) {
        if (null != rs ) {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("close rs error "+e,e);
            }
        }
        if (null != st) {
            try {
                st.close();
            } catch (SQLException e) {
                logger.debug("close st error " + e, e);
            }
        }
        if (null != con) {
            try {
                con.close();
            } catch (SQLException e) {
                logger.info("close con error " + e, e);
            }
        }
    }

    public void closeConn(PreparedStatement pstmt, Connection con) {
        if (null != pstmt) {
            try {
                pstmt.close();
            } catch (SQLException e) {
                logger.debug("close pstmt error " + e, e);
            }
        }
        if (null != con) {
            try {
                con.close();
            } catch (SQLException e) {
                logger.info("close con error " + e, e);
            }
        }
    }

}
